package landlords.helper;


import landlords.entity.Poker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PokerHelper {
    /*由薛晨飞，吴航博，魏嘉伟，齐阳完成了以下代码*/
    public static List<List<Poker>> distributePoker() {
        List<Poker> basePokers = createBasePokers();
        Collections.shuffle(basePokers);  // 洗牌

        List<List<Poker>> players = new ArrayList<>();

        for (int i = 1; i < 4; i++) {
            List<Poker> player = new ArrayList<>();
            for (int j = 1; j < 17; j++) {
                if (!basePokers.isEmpty()) {
                    player.add(basePokers.remove(0));  // 移除并添加到玩家手牌中
                } else {
                    break;  // 基础扑克牌为空，结束循环
                }
            }
            players.add(player);
        }

        // 添加最后一组三张作为公牌
        List<Poker> publicCards = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            if (!basePokers.isEmpty()) {
                publicCards.add(basePokers.remove(0));
            }
        }
        players.add(publicCards);

        return players;
    }

    private static List<Poker> createBasePokers() {
        /*由周子入，关晓宇，张睿泽，李嘉琦，梁琦完成了以下代码*/
        List<Poker> pokers = new ArrayList<>();
        String[] types = {"♠️", "♥️", "♦️", "♣️"};
        String[] levels = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};

        for (String type : types) {
            for (String level : levels) {
                pokers.add(new Poker(type, level));
            }
        }

        // 添加大小王
        pokers.add(new Poker("SMALL KING","🃏"));
        pokers.add(new Poker("BIG KING", "🃏"));

        return pokers;
    }
}
